<template>
  <el-dialog
    :title="formlist.id?'修改':'新增'"
    :visible="dialogVisible"
    width="30%"
    center
    @close="closeFn"
  >
    <el-form label-width="100px">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="formlist.username" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formlist.password" type="password" />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="formlist.email" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeFn">取 消</el-button>
      <el-button type="primary" @click="addform">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { Addformdata, alterformdata } from '@/api/employee'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formlist: {
        username: '',
        password: '',
        email: ''
      }
    }
  },
  methods: {
    closeFn() {
      this.$emit('update:dialogVisible', false)
      this.formlist = {
        username: '',
        password: '',
        email: ''
      }
    },
    // 新增&修改
    async addform() {
      if (this.formlist.id) {
        await alterformdata(this.formlist)
      } else {
        await Addformdata(this.formlist)
      }
      this.$emit('Automatic')
      this.$emit('update:dialogVisible', false)
    }
  }
}
</script>

<style>

</style>
